import unittest
from MasterMind import *

class PineTest(unittest.TestCase):
    
    ''' Teste de Pine '''

    def testInstaciacao(self):
        
         ''' Instaciacao: cor '''

         pine = Pine(1)
         assert isinstance(pine, Pine)
        
    def testGetColor(self):
        pine = Pine(1)
        assert pine.get_color() == 1
    
    def testCmp(self):
        pine = Pine(0)
        pine2 = Pine(1)
        pine3 = Pine(2)
        pine4 = Pine(2)
        assert pine < pine2
        assert pine3 > pine2
        assert pine3 == pine4
    
    def testStr(self):
        pine = Pine(1)
        assert str(pine) == '1'

class BlockTest(unittest.TestCase):

    ''' Teste de Block '''

    def testInstaciacao(self):
        block = Block(5)
        assert isinstance(block, Block)
            
    def testAddPine(self):
    	block = Block(5)
    	pine = Pine(1)
    	assert block.add_pine(pine, 0)
    	assert not block.add_pine(pine, 0)
    
    def testGetPine(self):
    	block = Block(5)
    	pine = Pine(1)
    	block.add_pine(pine, 0)
    	assert block.get_pine(0) == pine
    
    def testContains(self):
    	block = Block(5)
    	for position in xrange(5):	
    		block.add_pine(Pine(position), position)    	
    	pine = Pine(1)
    	assert block.contains(pine)
   
    def testCMP(self):
    	block = Block(5)
    	block2 = Block(5)
    	assert block == block2
    	for position in xrange(5):	
    		block.add_pine(Pine(position), position)
    	assert block != block2
    	
    def testResult_block(self):
    	block = Block(5)
    	block2 = Block(5)
    	for position in xrange(5):	
    		block.add_pine(Pine(position), position)
    	for position in xrange(4,-1, -1):
    		block2.add_pine(Pine(position + 1), position)
    	result = block.result_block(block2)
    	assert len(result) == 5
    	assert result.contains(Pine('white'))
    	assert not result.contains(Pine('black'))
    		    	
    
    def testLEN(self):
    	block = Block(5)
    	assert len(block) == 5      
         

if __name__ == "__main__":
    unittest.main()
    
    
